package com.mvd.app.activitys;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.kongzue.dialog.interfaces.OnMenuItemClickListener;
import com.kongzue.dialog.util.TextInfo;
import com.kongzue.dialog.v3.BottomMenu;
import com.kongzue.dialog.v3.MessageDialog;
import com.kongzue.dialog.v3.TipDialog;
import com.kongzue.dialog.v3.WaitDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.activity.BaseActivity;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.DateUtil;
import com.mvd.app.commons.JsonUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.CarItemEndModel;
import com.mvd.app.model.CarItemStartModel;
import com.mvd.app.model.CarsInforModel;
import com.mvd.app.model.CheckItemModel;
import com.mvd.app.model.CodeListModel;
import com.mvd.app.model.Item_2Model;
import com.mvd.app.model.ItemsModel;
import com.mvd.app.model.MyChoiceModel;
import com.mvd.app.model.UpdateCarStatusModel;
import com.mvd.app.model.WaiJainDataModel;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.iwgang.countuptime.CountupView;

import static com.mvd.app.application.BaseApplication.IsFirst;
import static com.mvd.app.application.BaseApplication.myChoiceModelList;
import static com.mvd.app.application.BaseApplication.mycar_checkItemlList;

//车辆唯一性检查
public class UniquenessActivity extends BaseActivity {
    public UniquenessActivity instances = null;
    @BindView(R.id.ac_uniqueness_online_carno)
    TextView acUniquenessOnlineCarno;
    @BindView(R.id.ac_uniqueness_SN)
    TextView acUniquenessSN;
    @BindView(R.id.ac_uniqueness_online_times)
    TextView acUniquenessOnlineTimes;
    @BindView(R.id.ac_uniqueness_line)
    TextView acUniquenessLine;
    @BindView(R.id.ac_uniqueness_haopai_haoma_fenlei)
    TextView acUniquenessHaopaiHaomaFenlei;
    @BindView(R.id.ac_uniqueness_cheliang_pinpai_xinghao)
    TextView acUniquenessCheliangPinpaiXinghao;
    @BindView(R.id.ac_uniqueness_cheliang_shibie_daihao)
    TextView acUniquenessCheliangShibieDaihao;
    @BindView(R.id.ac_uniqueness_fadongji_haoma)
    TextView acUniquenessFadongjiHaoma;
    @BindView(R.id.ac_uniqueness_cheliang_yanse_cheliang_waixing)
    TextView acUniquenessCheliangYanseCheliangWaixing;
    @BindView(R.id.ac_uniqueness_desc)
    EditText acUniquenessDesc;
    @BindView(R.id.ac_uniqueness_btn_end)
    Button acUniquenessBtnEnd;
    @BindView(R.id.ac_uniqueness_btn_start)
    Button acUniquenessBtnStart;
    @BindView(R.id.ac_uni_CountupViewTest3)
    CountupView acUniCountupViewTest3;

    String desc = "";//描述
    String line = "1";
    String error_msg = "", Item_Code = "UC", item_start_time = "", item_end_time = "";
    private String Login_name = "", login_IDNumber;//当前登录的检测员的名字
    private CarsInforModel carsInforModel;
    private WaiJainDataModel waiJainDataModel = new WaiJainDataModel();//外检上传数据model
    public List<CheckItemModel> weiyixing_code = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uniqueness);
        ButterKnife.bind(this);
        setBackBtn();
        setTopTitle("车辆唯一性检查");
        instances = this;
        String logStrf = "\n" + "onCreate-----车辆唯一性检查-----" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
        acUniquenessDesc.setCursorVisible(false);

        acUniCountupViewTest3.setTag("test2");
        long time1 = (long) 1000;
        acUniCountupViewTest3.start(time1);
        carsInforModel = (CarsInforModel) getIntent().getSerializableExtra("model_CarsInforModel");
        login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");
        Login_name = getIntent().getExtras().getString("login_w_name", "");
        line = getIntent().getExtras().getString("Car_Line", "");
        UtilsLog.e("车辆唯一性检查--carsInforModel====" + carsInforModel.toString());
        UtilsLog.e("车辆唯一性检查--login_IDNumber====" + login_IDNumber);
        UtilsLog.e("车辆唯一性检查--Login_name====" + Login_name);
        UtilsLog.e("车辆唯一性检查--line====" + line);

        acUniquenessLine.setText(line);
        if (carsInforModel != null) {
            //车牌号码
            if (!TextUtils.isEmpty(carsInforModel.getPlateRegion()) &&
                    !TextUtils.isEmpty(carsInforModel.getPlateNO())) {
                acUniquenessOnlineCarno.setText(carsInforModel.getPlateRegion() +
                        carsInforModel.getPlateNO());
            }
            //检验次数```````
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getTimes()))) {
                acUniquenessOnlineTimes.setText(carsInforModel.getTimes() + "次");
            }
            //SN
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getSN()))) {
                acUniquenessSN.setText(carsInforModel.getSN());
            }
        }

        if (myChoiceModelList != null && myChoiceModelList.size() > 0) {
            myChoiceModelList.clear();
        }
        List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
        Item_2Model item_2 = null;
        for (int i = 0; i < BaseApplication.checkItemModelList.size(); i++) {
            item_2 = new Item_2Model();
            item_2.setID(BaseApplication.checkItemModelList.get(i).getID());
            item_2.setCode1(BaseApplication.checkItemModelList.get(i).getCode1());
            item_2.setCode2(BaseApplication.checkItemModelList.get(i).getCode2());
            item_2.setName2(BaseApplication.checkItemModelList.get(i).getName2());
            Item_2Model_list.add(item_2);
        }
        for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
            for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k).getCode2())) {
                    Item_2Model_list.remove(j);
                }
            }
        }
        if (IsFirst) {
            for (int i = 0; i < Item_2Model_list.size(); i++) {
                // UtilsLog.e("Item_2Model_list=11=" + Item_2Model_list.get(i).toString());
                MyChoiceModel model = new MyChoiceModel();
                model.setCode2(Item_2Model_list.get(i).getCode2());
                model.setChecked(true);
                model.setName2(Item_2Model_list.get(i).getName2());
                model.setCode_key("Code2-" + Item_2Model_list.get(i).getCode2());
                model.setCode_values("0");
                myChoiceModelList.add(model);
            }
//            for (int i = 0; i < myChoiceModelList.size(); i++) {
//                UtilsLog.e("myChoiceModelList=11=" + myChoiceModelList.get(i).toString());
//            }
            getMyCarItems();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
        String logStrf = "\n" + "onDestroy-----车辆唯一性检查-----" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
        instances = null;
    }

    @OnClick({R.id.ac_uniqueness_line, R.id.ac_uniqueness_haopai_haoma_fenlei,
            R.id.ac_uniqueness_cheliang_pinpai_xinghao, R.id.ac_uniqueness_cheliang_shibie_daihao,
            R.id.ac_uniqueness_fadongji_haoma, R.id.ac_uniqueness_cheliang_yanse_cheliang_waixing,
            R.id.ac_uniqueness_desc, R.id.ac_uniqueness_btn_start,
            R.id.ac_uniqueness_btn_end})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_uniqueness_desc:
                //描述
                acUniquenessDesc.setCursorVisible(true);
                break;
//            case R.id.ac_uniqueness_line:
//                //检测线号
//                showMyDialog(line_str, R.id.ac_uniqueness_line);
//                break;
            case R.id.ac_uniqueness_haopai_haoma_fenlei:
                //号牌号码和分类 0-未检，1-合格，2-不合格，下同
                showMyDialog(he_ge_str, R.id.ac_uniqueness_haopai_haoma_fenlei);
                break;
            case R.id.ac_uniqueness_cheliang_pinpai_xinghao:
                //车辆品牌和型号
                showMyDialog(he_ge_str, R.id.ac_uniqueness_cheliang_pinpai_xinghao);
                break;
            case R.id.ac_uniqueness_cheliang_shibie_daihao:
                //车辆识别代号
                showMyDialog(he_ge_str, R.id.ac_uniqueness_cheliang_shibie_daihao);
                break;
            case R.id.ac_uniqueness_fadongji_haoma:
                //发动机号码
                showMyDialog(he_ge_str, R.id.ac_uniqueness_fadongji_haoma);
                break;
            case R.id.ac_uniqueness_cheliang_yanse_cheliang_waixing:
                //车辆颜色和车辆外形
                showMyDialog(he_ge_str, R.id.ac_uniqueness_cheliang_yanse_cheliang_waixing);
                break;
            case R.id.ac_uniqueness_btn_start:
                //项目开始
                line = acUniquenessLine.getText().toString().trim();
                desc = acUniquenessDesc.getText().toString().trim();
                getDataWaiJainStart();
//                Intent intent = new Intent(this, UniquenessPhotoActivity.class);
//                intent.putExtra("line", line);
//                intent.putExtra("desc", desc);
//                startActivity(intent);
                break;
            case R.id.ac_uniqueness_btn_end:
                //项目 end
                line = acUniquenessLine.getText().toString().trim();
                desc = acUniquenessDesc.getText().toString().trim();
                //上传平台的数据--项目结束
                initJsonDataToPlateform();
                break;
        }
    }


    private String[] line_str = new String[]{"1", "2", "3", "4", "5", "6"};
    private String[] he_ge_str = new String[]{"未检", "合格", "不合格"};

    private void showMyDialog(String[] str, final int id) {
//        BottomMenu bottomMenu= BottomMenu().build(this);
        BottomMenu.show(this, str, new OnMenuItemClickListener() {
            @Override
            public void onClick(String text, int index) {
                //返回参数 text 即菜单名称，index 即菜单索引
                UtilsLog.e("车辆唯一性---showMyDialog==" + text + "===" + index);
                switch (id) {
                    case R.id.ac_uniqueness_line:
                        // 线号
                        acUniquenessLine.setText(text);
                        break;
                    case R.id.ac_uniqueness_haopai_haoma_fenlei:
                        //号牌号码和分类 0-未检，1-合格，2-不合格，下同
                        acUniquenessHaopaiHaomaFenlei.setText(text);
                        break;
                    case R.id.ac_uniqueness_cheliang_pinpai_xinghao:
                        //车辆品牌和型号
                        acUniquenessCheliangPinpaiXinghao.setText(text);
                        break;
                    case R.id.ac_uniqueness_cheliang_shibie_daihao:
                        //车辆识别代号
                        acUniquenessCheliangShibieDaihao.setText(text);
                        break;
                    case R.id.ac_uniqueness_fadongji_haoma:
                        //发动机号码
                        acUniquenessFadongjiHaoma.setText(text);
                        break;
                    case R.id.ac_uniqueness_cheliang_yanse_cheliang_waixing:
                        //车辆颜色和车辆外形
                        acUniquenessCheliangYanseCheliangWaixing.setText(text);
                        break;
                }
            }
        }).setMenuTextInfo(new TextInfo().setBold(true).setFontColor(Color.BLACK).setGravity(Gravity.CENTER));
    }

    //item检测开始
    private void getDataWaiJainStart() {
        CarItemStartModel carItemStartModel = new CarItemStartModel();
        carItemStartModel.setPlatformSN(carsInforModel.getPlatformSN());
        carItemStartModel.setPlateType(carsInforModel.getPlateType());
//        carItemStartModel.setPlateNO(carsInforModel.getPlateNO());
//        if (SharedPreferencesUtils.getAddress(this).equals("温州")) {
//            carItemStartModel.setPlateNO(carsInforModel.getPlateRegion()
//                    + carsInforModel.getPlateNO()
//                    + carsInforModel.getPlateExtra());
//        } else if (SharedPreferencesUtils.getAddress(this).equals("常山")) {
        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion()
                + carsInforModel.getPlateNO());
//        }
//        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
//        data.get(position).getPlateRegion() + data.get(position).getPlateNO()
        carItemStartModel.setVIN(carsInforModel.getVIN());
        carItemStartModel.setDetectionID(String.valueOf(carsInforModel.getID()));
        carItemStartModel.setLine(line);
        carItemStartModel.setTest_times(carsInforModel.getTimes());
        carItemStartModel.setDetectionDevID("");
        carItemStartModel.setItemCode(Item_Code);
        item_start_time = "";
        item_start_time = DateUtil.currentTime2();
//        carItemStartModel.setDetectionItemStartDate(DateUtil.currentTime2());
        carItemStartModel.setDetectionItemStartDate(item_start_time);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(carItemStartModel);

//        String upjson_url = "{[" + jsonStr.substring(1, jsonStr.length() - 1) + "]}";
//        String upjson_url = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";

        String logStr = "\n" + "车辆唯一性检查---项目开始-json" + "\n" +
                "json::" + jsonStr + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + ITEM_START;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("车辆唯一性检查---jsonStr==" + jsonStr);
        UtilsLog.e("车辆唯一性检查---url==" + SharedPreferencesUtils.getIP(this) + ITEM_START);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + ITEM_START)
                .tag(this)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                        WaitDialog.show(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        WaitDialog.dismiss();
                        String result = response.body().trim();
                        UtilsLog.e("车辆唯一性检查--result==" + result);
                        UtilsLog.e("车辆唯一性检查--result=22=" + result.substring(1, result.length() -
                                1));
                        String logStr = "\n" + "车辆唯一性检查---项目开始---请求成功" + "\n" +
                                "result::" + response.body() + "\n" +
                                "URL::" + SharedPreferencesUtils.getIP(instances) + ITEM_START;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        CommonUtils.hideLoadingDialog(instances);
                        String str = result.substring(1, result.length() - 1);
                        if ("ok".equalsIgnoreCase(str)) {
//                        finish();
//                            Toast.makeText(instances, "联网项目开始成功", Toast.LENGTH_LONG)
//                                    .show();
                            TipDialog.show(instances, "车辆唯一性检查开始成功", TipDialog.TYPE.SUCCESS);
                        } else {
                            MessageDialog.show(instances, "提示", "车辆唯一性检查开始失败，请重试", "确定");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
                        String logStr2 = "\n" + "车辆唯一性检查---项目开始-onError" + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                        UtilsLog.e("联网查询-onError==" + response.body());
//                        CommonUtils.hideLoadingDialog(instances);
                        MessageDialog.show(instances, "提示", "车辆唯一性检查开始网络异常，请重试", "确定");
                    }
                });
    }

    //外检检测结束
    private void getDataWaiJainEnd() {
        CarItemEndModel carItemStartModel = new CarItemEndModel();
        carItemStartModel.setPlatformSN(carsInforModel.getPlatformSN());
        carItemStartModel.setPlateType(carsInforModel.getPlateType());
//        carItemStartModel.setPlateNO(carsInforModel.getPlateNO());
//        if (SharedPreferencesUtils.getAddress(this).equals("温州")) {
//            carItemStartModel.setPlateNO(carsInforModel.getPlateRegion()
//                    + carsInforModel.getPlateNO()
//                    + carsInforModel.getPlateExtra());
//        } else if (SharedPreferencesUtils.getAddress(this).equals("常山")) {
        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion()
                + carsInforModel.getPlateNO());
//        }
//        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
        carItemStartModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
        carItemStartModel.setVIN(carsInforModel.getVIN());
        carItemStartModel.setLine(line);
        carItemStartModel.setTest_times(carsInforModel.getTimes());
        carItemStartModel.setDetectionDevID("");
        carItemStartModel.setItemCode(Item_Code);
        item_end_time = "";
        item_end_time = DateUtil.currentTime2();
        carItemStartModel.setDetectionItemEndDate(item_end_time);
//        carItemStartModel.setDetectionItemEndDate(endTime);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(carItemStartModel);
//        String upjson_url = "{[" + jsonStr.substring(1, jsonStr.length() - 1) + "]}";
//        getDataWaiJainEnd_upjson_url = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";
        String logStr = "\n" + "车辆唯一性检查--项目结束---json" + "\n" +
                "json::" + jsonStr + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + ITEM_END;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getDataWaiJainEnd---jsonStr==" + jsonStr);
        UtilsLog.e("getDataWaiJainEnd---url==" + SharedPreferencesUtils.getIP(this) + ITEM_END);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + ITEM_END).tag(this)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataWaiJainEnd-result==" + result);
                        CommonUtils.hideLoadingDialog(instances);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataWaiJainEnd-newResult==" + newResult);
                        String logStr = "\n" + "车辆唯一性检查--项目结束--请求成功" + "\n" + "URL::" +
                                SharedPreferencesUtils.getIP(instances) + "" +
                                ITEM_END + "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if ("ok".equalsIgnoreCase(newResult)) {
                            EndAllItem(String.valueOf(carsInforModel.getID()));
//                            TipDialog.show(instances, "车辆唯一性检查结束成功", TipDialog.TYPE.SUCCESS);
//                            Handler handler = new Handler();
//                            handler.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
////                                    finish();
//                                    Intent intent = new Intent();
//                                    intent.putExtra("nq", 1);
//                                    instances.setResult(102, intent);
//                                    instances.finish();
//                                }
//                            }, 1200);//后执行Runnable中的run方法
                        } else {
                            MessageDialog.show(instances, "提示", "车辆唯一性检查结束失败，请重试", "确定");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataWaiJainEnd-onError==" + response.body());
                        String logStr = "\n" + "车辆唯一性检查--项目结束--onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_END + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        MessageDialog.show(instances, "提示", "车辆唯一性检查网络异常，请重试", "确定");
                    }
                });
    }

    void initJsonDataToPlateform() {
        WaitDialog.show(instances, "加载中...");
        waiJainDataModel.setReplaceEngineType(carsInforModel.getReplaceEngineType());
        waiJainDataModel.setReplaceEngineNO(carsInforModel.getReplaceEngineNO());
        waiJainDataModel.setUCResultNote(desc);
        waiJainDataModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
        waiJainDataModel.setGUID(carsInforModel.getGUID());
        waiJainDataModel.setDetectionDevID(CommonUtils.getIMEI(this));
        waiJainDataModel.setBrakeForce(carsInforModel.getBrakeForce());
//        if (SharedPreferencesUtils.getAddress(this).equals("温州")) {
//            waiJainDataModel.setPlateNO(carsInforModel.getPlateRegion()
//                    + carsInforModel.getPlateNO()
//                    + carsInforModel.getPlateExtra());
//        } else if (SharedPreferencesUtils.getAddress(this).equals("常山")) {
        waiJainDataModel.setPlateNO(carsInforModel.getPlateRegion()
                + carsInforModel.getPlateNO());
//        }
//        waiJainDataModel.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
        waiJainDataModel.setAirAdmission(carsInforModel.getAirAdmission());
        try {
            String name = URLDecoder.decode(Login_name, "UTF-8");
            waiJainDataModel.setAppearanceInspector(name);//检测员名字，汉字
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        waiJainDataModel.setAppearanceNo(login_IDNumber);
        waiJainDataModel.setApprovedLoad(carsInforModel.getApprovedLoad());
        waiJainDataModel.setArea(carsInforModel.getArea());
        waiJainDataModel.setBodyColor(carsInforModel.getBodyColor());
        waiJainDataModel.setBrand(carsInforModel.getBrand());
        waiJainDataModel.setCarBodyType(carsInforModel.getCarBodyType());
        waiJainDataModel.setCarID(carsInforModel.getCarID());
        waiJainDataModel.setCarModel(carsInforModel.getCarModel());
        waiJainDataModel.setCarTypeLevel(carsInforModel.getCarTypeLevel());
        waiJainDataModel.setCategory(carsInforModel.getCategory());
        waiJainDataModel.setCentralAxle(carsInforModel.getCentralAxle());
        waiJainDataModel.setCode(carsInforModel.getCode());
        waiJainDataModel.setCombCarNO(carsInforModel.getCombCarNO());
        waiJainDataModel.setCurbWeight(carsInforModel.getCurbWeight());
        waiJainDataModel.setDetectDate(carsInforModel.getDetectDate());
        waiJainDataModel.setDetectionCategory(carsInforModel.getDetectionCategory());
        waiJainDataModel.setDetectionStatus(carsInforModel.getDetectionStatus());
        waiJainDataModel.setDisplacement(carsInforModel.getDisplacement());
        waiJainDataModel.setDriveAxle(carsInforModel.getDriveAxle());
        waiJainDataModel.setDriverAxleWeight(carsInforModel.getDriverAxleWeight());
        waiJainDataModel.setDriverTypeName(carsInforModel.getDriverTypeName());
        waiJainDataModel.setDriverType(carsInforModel.getDriverType());
        waiJainDataModel.setPlateType(carsInforModel.getPlateType());
        waiJainDataModel.setItemcode(Item_Code);
        waiJainDataModel.setLine(line);
        waiJainDataModel.setMainAxis(carsInforModel.getMainAxis());
        waiJainDataModel.setParkingAxle(carsInforModel.getParkingAxle());
        waiJainDataModel.setEngineNO(carsInforModel.getEngineNO());
        waiJainDataModel.setFuelType(carsInforModel.getFuelType());
        waiJainDataModel.setPlateTypeName(carsInforModel.getPlateTypeName());
        waiJainDataModel.setPlatformSN(carsInforModel.getPlatformSN());
        waiJainDataModel.setQueueID(carsInforModel.getQueueID());
        waiJainDataModel.setSN(carsInforModel.getSN());
        waiJainDataModel.setStatus(carsInforModel.getStatus());
        waiJainDataModel.setTest_times(carsInforModel.getTimes());
        waiJainDataModel.setType(carsInforModel.getType());
        waiJainDataModel.setVIN(carsInforModel.getVIN());
        waiJainDataModel.setDataType(Item_Code);
        waiJainDataModel.setOwner(carsInforModel.getOwner());
        waiJainDataModel.setTelephone(carsInforModel.getTelephone());
        waiJainDataModel.setAddress(carsInforModel.getAddress());
        waiJainDataModel.setMemo("");
        uploadPlatformData(waiJainDataModel);
    }

    //外检上传平台数据
    String upjson_url;

    private void uploadPlatformData(WaiJainDataModel waiJainDataModel) {
        Gson gson = new Gson();
        String jsonStr = gson.toJson(waiJainDataModel);
//        upjson_url = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "," +
//                appendCode2AndValues() + "}]";
//        upjson_url = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "," +
//                codeStr2() + "}]";
        upjson_url = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "," +
                result_code + "}]";

        UtilsLog.e("车辆唯一性检查--上传平台数据---jsonStr==" + upjson_url);
        UtilsLog.e("车辆唯一性检查--上传平台数据---url==" + SharedPreferencesUtils.getIP(this) + PLAT_FORM_DATA);
        String logStr = "\n" + "车辆唯一性检查--上传平台数据---json" + "\n" +
                "json::" + upjson_url + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + PLAT_FORM_DATA;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + PLAT_FORM_DATA).tag(this)
                .upJson(upjson_url)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("车辆唯一性检查--上传平台数据--result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("车辆唯一性检查--上传平台数据--newResult==" + newResult);
                        String logStr = "\n" + "车辆唯一性检查--上传平台数据---请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                PLAT_FORM_DATA + "\n" + "JSON::" + upjson_url +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if ("ok".equalsIgnoreCase(newResult)) {
                            Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    uploadBuHeGeData();
//                                    updateCarStatusInfor();
                                }
                            }, 100);//后执行Runnable中的run方法
                        } else {
                            MessageDialog.show(instances, "提示", "上传平台数据失败，请重试", "确定");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("联网查询--上传平台数据-onError==" + response.body());
                        String logStr = "\n" + "车辆唯一性检查--上传平台数据--onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                PLAT_FORM_DATA + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        MessageDialog.show(instances, "提示", "上传平台数据网络异常，请重试", "确定");
                    }
                });
    }

    private String getHeGeStatement(String str) {
        String result = "1";
        if (str.equals("合格")) {
            result = "1";
        } else if (str.equals("不合格")) {
            result = "2";
        } else if (str.equals("未检")) {
            result = "0";
        }
        return result;
    }

    private String getHeGe(String str) {
        String result = "1";
        if (str.equals("1")) {
            result = "1";
        } else if (str.equals("2")) {
            result = "2";
        } else if (str.equals("0")) {
            result = "0";
        }
        return result;
    }

    //拼装json  --Code2
    private String appendCode2AndValues() {
        String Code2JsonStr = "";
        String result = "";
        if (myChoiceModelList != null && myChoiceModelList.size() > 0) {
            for (int i = 0; i < myChoiceModelList.size(); i++) {
                //号牌号码和分类
                String str2 = acUniquenessHaopaiHaomaFenlei.getText().toString().trim();
                //车辆品牌和型号
                String str3 = acUniquenessCheliangPinpaiXinghao.getText().toString().trim();
                //车辆识别代号
                String str4 = acUniquenessCheliangShibieDaihao.getText().toString().trim();
                //发动机号码
                String str5 = acUniquenessFadongjiHaoma.getText().toString().trim();
                //车辆颜色和车辆外形
                String str6 = acUniquenessCheliangYanseCheliangWaixing.getText().toString().trim();

                if (myChoiceModelList.get(i).getCode_key().equals("Code2-2")) {
                    myChoiceModelList.get(i).setCode_values(getHeGeStatement(str2));
                }

                if (myChoiceModelList.get(i).getCode_key().equals("Code2-3")) {
                    myChoiceModelList.get(i).setCode_values(getHeGeStatement(str3));
                }

                if (myChoiceModelList.get(i).getCode_key().equals("Code2-4")) {
                    myChoiceModelList.get(i).setCode_values(getHeGeStatement(str4));
                }
                if (myChoiceModelList.get(i).getCode_key().equals("Code2-5")) {
                    myChoiceModelList.get(i).setCode_values(getHeGeStatement(str5));
                }
                if (myChoiceModelList.get(i).getCode_key().equals("Code2-6")) {
                    myChoiceModelList.get(i).setCode_values(getHeGeStatement(str6));
                }
                Code2JsonStr = Code2JsonStr + "\"" + myChoiceModelList.get(i).getCode_key() + "\""
                        + ":" + "\"" + myChoiceModelList.get(i).getCode_values() + "\"" + ",";
            }
//            UtilsLog.e("Code2JsonStr==" + Code2JsonStr);
            UtilsLog.e("车辆唯一性检查--==Code2JsonStr=22=" + Code2JsonStr.substring(0, Code2JsonStr.length() - 1));
        }
        if (Code2JsonStr.length() > 0) {
            result = Code2JsonStr.substring(0, Code2JsonStr.length() - 1);
        }
        String logStr = "\n" + "车辆唯一性检查--appendCode2AndValues---json" + "\n" +
                "json::" + result + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("车辆唯一性检查--==appendCode2AndValues==" + result);
        return result;
    }

    public String codeStr2() {
        String result = "";
        //号牌号码和分类
        String str2 = acUniquenessHaopaiHaomaFenlei.getText().toString().trim();
        //车辆品牌和型号
        String str3 = acUniquenessCheliangPinpaiXinghao.getText().toString().trim();
        //车辆识别代号
        String str4 = acUniquenessCheliangShibieDaihao.getText().toString().trim();
        //发动机号码
        String str5 = acUniquenessFadongjiHaoma.getText().toString().trim();
        //车辆颜色和车辆外形
        String str6 = acUniquenessCheliangYanseCheliangWaixing.getText().toString().trim();
//
//        if (myChoiceModelList.get(i).getCode_key().equals("Code2-2")) {
//            myChoiceModelList.get(i).setCode_values(getHeGeStatement(str2));
//        }
//
//        if (myChoiceModelList.get(i).getCode_key().equals("Code2-3")) {
//            myChoiceModelList.get(i).setCode_values(getHeGeStatement(str3));
//        }
//
//        if (myChoiceModelList.get(i).getCode_key().equals("Code2-4")) {
//            myChoiceModelList.get(i).setCode_values(getHeGeStatement(str4));
//        }
//        if (myChoiceModelList.get(i).getCode_key().equals("Code2-5")) {
//            myChoiceModelList.get(i).setCode_values(getHeGeStatement(str5));
//        }
//        if (myChoiceModelList.get(i).getCode_key().equals("Code2-6")) {
//            myChoiceModelList.get(i).setCode_values(getHeGeStatement(str6));
//        }
        result = "\"Code2-2\":" + getHeGeStatement(str2) + "," + "\"Code2-3\":" + getHeGeStatement(str3) + ","
                + "\"Code2-4\":" + getHeGeStatement(str4) + "," + "\"Code2-5\":" + getHeGeStatement(str5) + "," +
                "\"Code2-6\":" + getHeGeStatement(str6);
        return result;
    }

    //获取需要检测的人工检验项目接口
    private void getMyCarItems() {
        ItemsModel model = new ItemsModel();
        model.setCarType(carsInforModel.getType());
        model.setDetectCategroy(carsInforModel.getDetectionCategory());
        model.setPassengerNb(carsInforModel.getApprovedLoad());
        model.setPlateType(carsInforModel.getPlateType());
        model.setVehicleID(String.valueOf(carsInforModel.getVehicleID()));

        String registerTime = carsInforModel.getRegisteDate();
        String str = registerTime.substring(6, registerTime.length() - 2).trim();
        String registerdate = DateUtil.getDateTimeFromMillisecond(Long.parseLong(str));
        model.setRegisteDate(registerdate);
        Gson gson = new Gson();
        String json_str = gson.toJson(model);
        UtilsLog.e("车辆唯一性检查---getMyCarItems---json_str==" + json_str);
        String url = "";
//        if(SharedPreferencesUtils.get38900(instances)){
        url = GET_MY_ITEM_38900;
//        }else{
//            url=GET_MY_ITEM_;
//        }
        UtilsLog.e("getMyCarItems---url==" + SharedPreferencesUtils.getIP(this) + url);
        String logStr = "\n" + "车辆唯一性检查--外检--获取需要检测的人工检验项目接口--请求" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                url + "\n" + "JSON::" + json_str + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + url).tag(this)
                .upJson(json_str)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getMyCarItems-newResult==" + newResult);
                        String logStrf = "\n" + "外检--获取需要检测的人工检验项目接口--请求成功" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());

                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
                            List<CheckItemModel> DiPanDongTai_checkItemlList = new ArrayList<>();
                            mycar_checkItemlList = new ArrayList<CheckItemModel>();
                            weiyixing_code = new ArrayList<CheckItemModel>();
//                            mycar_checkItemlList = JsonUtil.stringToArray(newResult,
//                                    CheckItemModel[].class);
                            DiPanDongTai_checkItemlList = JsonUtil.stringToArray(newResult,
                                    CheckItemModel[].class);
                            if (DiPanDongTai_checkItemlList != null && DiPanDongTai_checkItemlList.size() > 0) {

                                //给是否拍照列表赋值，初始化
//                                for (int i = 0; i < DiPanDongTai_checkItemlList.size(); i++) {
//                                    IsTakePhoto.add(false);
//                                }

                                List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
                                Item_2Model item_2 = null;
                                for (int i = 0; i < DiPanDongTai_checkItemlList.size(); i++) {
                                    if (!DiPanDongTai_checkItemlList.get(i).getCode1().equals("6")) {
                                        mycar_checkItemlList.add(DiPanDongTai_checkItemlList.get(i));
                                        item_2 = new Item_2Model();
                                        item_2.setID(DiPanDongTai_checkItemlList.get(i).getID());
                                        item_2.setCode1(DiPanDongTai_checkItemlList.get(i).getCode1());
                                        item_2.setCode2(DiPanDongTai_checkItemlList.get(i).getCode2());
                                        item_2.setName2(DiPanDongTai_checkItemlList.get(i).getName2());
                                        Item_2Model_list.add(item_2);
                                    }
                                    if (DiPanDongTai_checkItemlList.get(i).getCode1().equals("2")) {
                                        weiyixing_code.add(DiPanDongTai_checkItemlList.get(i));
                                    }

                                }
                                if (weiyixing_code != null && weiyixing_code.size() > 0) {
                                    setCode2();
                                }
                                for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
                                    for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                                        if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k)
                                                .getCode2())) {
                                            Item_2Model_list.remove(j);
                                        }
                                    }
                                }
//
                                for (int i = 0; i < myChoiceModelList.size(); i++) {
                                    String Code2 = myChoiceModelList.get(i).getCode2().toString().trim();
                                    for (int j = 0; j < Item_2Model_list.size(); j++) {
                                        String code2_my = Item_2Model_list.get(j).getCode2().toString()
                                                .trim();
                                        if (Code2.equals(code2_my)) {
                                            myChoiceModelList.get(i).setCode_values(Item_2Model_list.get(j).getFlag());
//                                            myChoiceModelList.get(i).setCode_values("1");
                                        }
                                    }
                                }

                            } else {
                                UtilsLog.e("getMyCarItems-Result==没有获取到当前车辆检测到的项目");
                            }
                        } else {
                            UtilsLog.e("getGET_ALL_ITEMList-result==" + "没有数据");
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getMyCarItems-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                        String logStrf = "\n" + "车辆唯一性检查--外检--获取需要检测的人工检验项目接口--请求失败--error" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
                    }
                });
    }

    String result_code = "";

    String setCode2() {
        String re2 = "", re3 = "", re4 = "", re5 = "", re6 = "";
        UtilsLog.e("车辆唯一性检查---weiyixing_code==" + weiyixing_code.toString());
        for (int i = 0; i < weiyixing_code.size(); i++) {
            String myflag=weiyixing_code.get(i).getFlag();
            String mycode2=weiyixing_code.get(i).getCode2();
//            UtilsLog.e("车辆唯一性检查---myflag=====" + myflag+"==是否整数=="+CommonUtils.isNumeric(myflag));
            if (mycode2.equals("2")) {
                re2 = myflag;
            } else if (mycode2.equals("3")) {
                re3 = myflag;
            } else if (mycode2.equals("4")) {
                re4 = myflag;
            } else if (mycode2.equals("5")) {
                re5 = myflag;
            } else if (mycode2.equals("6")) {
                re6 = myflag;
            }
        }

        UtilsLog.e("车辆唯一性检查---setCode2==" + re2+"==="+re3+"==="+re4+"==="+re5+"==="+re6);

        result_code = "\"Code2-2\":" + re2.toString() + "," + "\"Code2-3\":" + re3 + ","
                + "\"Code2-4\":" + re4 + "," + "\"Code2-5\":" + re5 + "," +"\"Code2-6\":" + re6;
        UtilsLog.e("车辆唯一性检查---result_code==" + result_code);
        return result_code;
    }

    String jsonStr22;

    public void updateCarStatusInfor() {
        UpdateCarStatusModel model = new UpdateCarStatusModel();
        model.setType(0);
        model.setAppearanceInspector(Login_name);
        model.setQueueID(String.valueOf(carsInforModel.getID()));
        model.setUCStatus("1");
        Gson gson = new Gson();
        jsonStr22 = gson.toJson(model);
        String logStr = "\n" + "车辆唯一性检查--更新车辆状态---json--" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                UPDATE_CAR_STATUS + "\n" + "JSON::" + jsonStr22 + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("updateCarStatusInfor---jsonStr==" + jsonStr22);
        UtilsLog.e("updateCarStatusInfor---url==" + SharedPreferencesUtils.getIP(this) + UPDATE_CAR_STATUS);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + UPDATE_CAR_STATUS)
                .tag(this)
                .upJson(jsonStr22)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body().trim();
                        UtilsLog.e("updateCarStatusInfor-result==" + result);
                        UtilsLog.e("updateCarStatusInfor-result=22=" + result.substring(1, result.length() -
                                1));
                        String logStr = "\n" + "车辆唯一性检查--外检项目更新状态--onSuccess" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                UPDATE_CAR_STATUS + "\n" + "JSON::" + jsonStr22 + "\n" + "result::" +
                                response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        if ("ok".equalsIgnoreCase(newResult)) {
                            getDataWaiJainEnd();
//                            Handler handler = new Handler();
//                            handler.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
//                                    getDataWaiJainEnd();
//                                }
//                            }, 800);//后执行Runnable中的run方法
                        } else {
                            MessageDialog.show(instances, "提示", "更新车辆状态失败，请重试", "确定");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataWaiJainStart-onError==" + response.body());
                        String logStr = "\n" + "车辆唯一性检查--外检项目更新状态-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                UPDATE_CAR_STATUS + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }


    String setBuHeGeItem() {
        String myjson = "";
        CodeListModel codeListModel = null;
        List<CodeListModel> codeList_list = new ArrayList<>();
        codeListModel = new CodeListModel();
        codeListModel.setDataType("UC");
        codeListModel.setGUID(carsInforModel.getGUID());
        codeListModel.setUCResultNote(desc);
        codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
        codeListModel.setTest_times(carsInforModel.getTimes());
        codeListModel.setUnqualified_Code1("0");
        codeListModel.setUnqualified_Code2("0");
        codeListModel.setUnqualified_Code3("0");
        codeList_list.add(codeListModel);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
        myjson = jsonStr;
        UtilsLog.e("车辆唯一性检查--reportedJsonStr555==" + myjson);
        return myjson;
    }

    //外检不合格项目-增加外检记录接口
    private void uploadBuHeGeData() {
//        Gson gson = new Gson();
        String jsonStr = setBuHeGeItem();
        UtilsLog.e("车辆唯一性检查--uploadDataByWaiJianItem---jsonStr==" + jsonStr);
        UtilsLog.e("车辆唯一性检查--uploadDataByWaiJianItem---url==" + SharedPreferencesUtils.getIP(this) + WAIJIAN_ADD_RECORED);
        String logStr = "\n" + "车辆唯一性检查--外检不合格项目-增加外检记录接口--uploadDataByWaiJianItem--请求" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                WAIJIAN_ADD_RECORED + "\n" + "JSON::" + jsonStr + "\n";
//        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + WAIJIAN_ADD_RECORED).tag(this)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("车辆唯一性检查--uploadDataByWaiJianItem-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("车辆唯一性检查--uploadDataByWaiJianItem-newResult==" + newResult);
                        CommonUtils.hideLoadingDialog(instances);
                        String logStrf = "\n" + "车辆唯一性检查--外检不合格项目-增加外检记录接口--uploadDataByWaiJianItem--请求成功" +
                                "\n" + "result::" + response.body();
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
                        if ("ok".equalsIgnoreCase(newResult)) {
                            //项目总结束
                            updateCarStatusInfor();

//                            Handler handler = new Handler();
//                            handler.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
//                                    EndAllItem(String.valueOf(carsInforModel.getID()));
//                                }
//                            }, 700);//后执行Runnable中的run方法
//                            instances.finish();
//                            Toast.makeText(instances, "提交成功", Toast
//                                    .LENGTH_LONG).show();
                        } else {
                            Toast.makeText(instances, "车辆唯一性检查项目数据提交失败，请重试", Toast
                                    .LENGTH_LONG).show();
                        }

                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("联网查询--uploadDataByWaiJianItem-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                        String logStr = "\n" + "联网查询--外检不合格项目-增加外检记录接口--uploadDataByWaiJianItem-onError-失败" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }
                });
    }


    /**
     * 项目总结束接口,最后一个执行
     */
    private void EndAllItem(final String detectionID) {
        UtilsLog.e("项目总结束接口=======");
        UtilsLog.e("EndAllItem---url==" + SharedPreferencesUtils.getIP(instances) + ITEM_ALL_END +
                detectionID + "/DetectionID");
        OkGo.<String>get(SharedPreferencesUtils.getIP(instances) + ITEM_ALL_END +
                detectionID + "/DetectionID").tag(instances)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        //完成按钮可点击
//                        acWaijianBtnWancheng2.setEnabled(true);

                        CommonUtils.hideLoadingDialog(instances);
                        String result = response.body();
                        UtilsLog.e("EndAllItem-result==" + result);
                        String logStr = "\n" + "外检项目总结束:总结束:总结束--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_ALL_END + detectionID + "/DetectionID" +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

                        TipDialog.show(instances, "车辆唯一性检查结束成功", TipDialog.TYPE.SUCCESS);
                        Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
//                                    finish();
                                Intent intent = new Intent();
                                intent.putExtra("nq", 1);
                                instances.setResult(102, intent);
                                instances.finish();
                            }
                        }, 1000);//后执行Runnable中的run方法

//                        Toast.makeText(instances, "外检项目完成", Toast
//                                .LENGTH_LONG).show();
//                        updateCarStatusInfor();
//                        finish();

//                        if ("\"ok\"".equals(result)) {
//
//                            updateCarStatusInfor_anjian(1);
//                            Toast.makeText(instances, "外检项目完成", Toast
//                                    .LENGTH_LONG).show();
//
//                        } else {
//                            showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
//                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        String logStr = "\n" + "外检项目总结束:总结束:总结束-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_ALL_END + detectionID + "/DetectionID" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        UtilsLog.e("EndAllItem-onError==" + response.body());
                        UtilsLog.e("EndAllItem-onError==" + response.getException());
//                        CommonUtils.hideLoadingDialog(An_Huan_HomeActivity.this);
                        MessageDialog.show(instances, "提示", "车辆下线失败，请重试，如果还未成功请联系管理员");
//                        showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }
}
